package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 订单
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    //todo 提交订单
    @PostMapping("/submit")
    public R submit(@RequestBody Orders orders){

        //返回支付链接
        return orderService.submit(orders);
    }
    //todo 查看个人中心
    @GetMapping("/userPage")
    public R findPage(Integer page,Integer pageSize){
        R r = orderService.findPage(page,pageSize);
        return r;
    }

    //查询订单的状态
    @GetMapping("/findStatusById")
    public R findStatusById(String orderId){

        Orders orders = orderService.getById(Long.parseLong(orderId));
        if (orders.getStatus() == 2){//代表支付成功
            return R.success("订单已支付");
        }
        return R.error("订单未支付");

    }

}
